<template>
  <div>
    <router-view v-slot="{ Component }" ref="con">
      <keep-alive :include="keepAlive">
        <component class="child-view" :is="Component"/>
      </keep-alive>
    </router-view>
    <van-tabbar v-model="active">
      <van-tabbar-item name="home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item name="mine" icon="setting-o">个人中心</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script setup>
import {computed, getCurrentInstance, nextTick, onMounted, ref, watch} from "vue";
import {useStore} from "vuex";
const { proxy } = getCurrentInstance()

const props = defineProps({

})

const store = useStore()

const keepAlive = computed(() => store.state.keepAlive)

const active = ref('home')

watch(() => active.value, (name) => {
  store.commit('switchTab', 'main-' + name)
})

proxy.$bus.on('tab-active', (name) => {
  active.value = name.substring(5)
})

</script>

<style scoped>

</style>
